package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassNameShopController
 * @Description  店铺相关接口
 * @Author钰玟
 * @Date2025/2/14 下午9:42
 * @Version 1.0
 **/
@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
public class ShopController {

    private static final String KEY = "SHOP_STATUS";

    @Autowired
    RedisTemplate redisTemplate;

    /**
     * 设置店铺状态
     * @param status 店铺状态 1营业，0打样
     * @return Result
     */
    @PutMapping("/{status}")
    @ApiOperation("设置店铺状态")
    public Result setShopStatus(@PathVariable Integer status) {
        log.info("设置店铺状态:{}",status==1 ? "营业" : "打样");
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success();
    }

    /**
     *  获取店铺状态
     * @return Result<Integer>
     */
    @GetMapping("/status")
    @ApiOperation("获取店铺状态")
    public Result<Integer> getShopStatus() {
        log.info("获取店铺状态");
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        return Result.success(status);
    }

}
